#  导包
import unittest
from api.employee import EmployeeAPI
from utils import common_assert


# 创建测试类
class EmployeeTest(unittest.TestCase):

    employee_id = None

    # 前置处理：实例化
    def setUp(self):
        self.employee_api = EmployeeAPI

    #  添加员工测试用例设计
    def test01_add_employee(self):
        add_employee_data = {

            "username":"jack0709t0728004",
            "mobile":"13212072804",
            "timeofEntry":"2020-07-09",
            "formofEployment":1,
            "workNumber":"072804",
            "departmentName":"销售",
            "departmentId":"1266699057968001024",
            "correctionTime":"2020-07-30t16:00:00.000z"
        }

        #获取响应结果
        response=self.employee_api.add_employee(add_employee_data=add_employee_data)
        print(response.json())

        # 断言
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(True, response.json().get("success"))
        # self.assertEqual(10000, response.json().get("code"))
        # self.assertIn("操作成功", response.json().get("message"))
        common_assert(self, response)   #直接使用公共断言方法的默认值

        # 提取员工ID
        EmployeeTest.employee_id = response.json().get("data").get("id")
        print(EmployeeTest.employee_id)

        # 修改员工测试用例
    def test02_update_employee(self):
        update_employee_data = {
            "username":"rose0728"
        }
        response = self.employee_api.update_employee(EmployeeTest.employee_id,update_data=update_employee_data)
        print(response.json())

        common_assert(self, response)   #直接使用公共断言方法的默认值


    def test03_get_employee(self):

        response = self.employee_api.get_employee(EmployeeTest.employee_id)
        print(response.json())

        common_assert(self, response)   #直接使用公共断言方法的默认值


    def test04_delete_employee(self):

        response = self.employee_api.delete_employee(EmployeeTest.employee_id)
        print(response.json())

        common_assert(self, response)   #直接使用公共断言方法的默认值
